package com.mdlib.helper.api;

import android.app.Activity;

import com.mdlib.helper.api.network.RxHelper;
import com.mdlib.helper.api.network.RxSubscribe;
import com.mdlib.helper.model.entity.UpdateInfo;
import com.mdlib.helper.module.update.AppUpdate;
import com.mdlib.helper.utils.ToastUtil;

/**
 * 作者：HQY on 16/12/19 16:34
 * 邮箱：hqy_xz@126.com
 */

public class MDUpDateApp extends MDPresenter {


    public static void upDateApp(final Activity activity, final boolean isShow) {
        addSubscribe(DataManager.getInstance().getUserApi()
                .getVersion("1")
                .compose(RxHelper.<UpdateInfo>defaultHandleResult())
                .subscribe(new RxSubscribe<UpdateInfo>() {
                    @Override
                    protected void onSucc(UpdateInfo updateInfo) {
                        new AppUpdate(activity, isShow, updateInfo).checkUpdate();
                    }

                    @Override
                    protected void onFail(String msg) {
                        if (isShow) {
                            ToastUtil.showToast("已经是最新版本了");
                        }
                    }
                }));
    }


    @Override
    public void onDestory() {
        unSubscribe();
    }


}
